package top.todu.leaning.opentelemetry_loki.config;

import io.opentelemetry.api.trace.Span;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.AsyncHandlerInterceptor;

//WebMvcConfigurerAdapter
@Component
public class TraceResponseHandler implements AsyncHandlerInterceptor {

  @Override
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
      throws Exception {
    response.addHeader("X-IoTOS-Trace-Id", Span.current().getSpanContext().getTraceId());
    return true;
  }
}
